package com.ita.iosa.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.junit.Test;

import com.ita.iosa.po.Merchant;

public class XmlResolverUtil {

	public Merchant XMLToMerchant(TextMessage msg)  {
		SAXBuilder builder = new SAXBuilder();
		//TextMessage msg = recieveXML();
		Document doc;
		Merchant m = new Merchant();
		try {
			doc = builder.build(new ByteArrayInputStream(msg.getText()
					.getBytes()));
			
			Element root = doc.getRootElement();
			List<Element> es = root.getChildren();
			m.setMname(new String(es.get(0).getText().getBytes("utf8"), "utf8"));
			m.setType(es.get(1).getText());
			m.setAddress(es.get(2).getText());
			m.setTel(es.get(3).getText());
			m.setLogo(es.get(4).getText());
			m.setInfo(es.get(5).getText());
			m.setEmail(es.get(6).getText());
			m.setPassword(es.get(7).getText());
			m.setMid(Integer.valueOf(es.get(8).getText()));
		} catch (JDOMException | IOException | JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return m;
	}
}
